All Questions
12 questions
0votes
2answers
343views
How to refactor this tightly-coupled method and (mostly) preserve its encapsulation?
I have recently encountered this problematic method (minimal reproducible sample in C++ but this question aims to be language agnostic past the syntax): void MyObject::twice_bind_cycle() { _bind1()...
0votes
4answers
320views
Object matching using generic method? [closed]
I have a piece of code where two objects (incoming request object and a profile object) are to be checked for matching conditions. So the first method is as below where I check whether the profile ...
1vote
1answer
133views
Proxy / Decorator Design pattern scalability to a lot of methods
I'm trying to solve a common problem of logging each method that calls 3rd party operation and I don't understand how to scale it up. Current implementation: public class ElasticsearchClient { ...
1vote
2answers
848views
Design pattern for executing and reverting the tasks in same order
I have a Task in my project , to complete that i have call(REST) multiple external systems. If my call fails at some level , i have to rollback all my previous calls(making call with undo action) . ...
1vote
1answer
106views
How should I integrate routine history tracking feature with the routine itself
Let's say I am writing code to run a machine similar to a 3D printer and I have a routine like: machine.moveTo(x1, y1); machine.alignByCamera(); machine.heatUp(); machine.extrude(amount1); machine....
8votes
2answers
11kviews
Doesn't repository pattern in clean architecture violate Dependency inversion principle?
From what I have read and seen clean architecture assumes that you have some entities which know nothing about persistence though at the same layer as they reside there might be an interface which has ...
1vote
1answer
157views
How to model either relationship?
I am working on a project where a user can send email to either a contact from his directory (Internal) or type an email address explicitly (External Contact) or a mix of both. We also show the read ...
30votes
7answers
13kviews
Is it a code smell to set a flag in a loop to use it later?
I have a piece of code where I iterate a map until a certain condition is true and then later on use that condition to do some more stuff. Example: Map<BigInteger, List<String>> map = ...
1vote
4answers
311views
How to refactor this legacy code snippet to make it extensible? [closed]
I've come across a method resembling the below snippet. public void process(Data row) { Value value1 = row.getValue1(); Value value2 = row.getValue2(); boolean saved = false; if (...
0votes
1answer
282views
Interface Implementation: A parameter I don't need
Pseudo-Code interface IPagingInfo { int CurrentPageNo { get; } int RowsPerPage { get; } ... } interface ResultsRetriver { ResultRows GetResults(IPagingInfo pagingInfo); } class ...
2votes
1answer
257views
Interface Design: Specific vs General parameter (A Minimal design vs anticipated use variation)
Code public interface IVehicle { string VehicleMake { get; } int MonthsSincePurchase { get; } bool IsApprovedUsed { get; } ... } public class WarrantyPopUpHandler { virtual bool ...
11votes
4answers
2kviews
Do I suffer from encapsulation overuse?
I have noticed something in my code in various projects that seems like code smell to me and something bad to do, but I can't deal with it. While trying to write "clean code" I tend to over-use ...